/******************************************************************************
 * (C) Copyright 2013 Atech-Automotive
 * FILE NAME:    uds_can_trans.h
 * DESCRIPTION:
 * 
 * DATE BEGUN:   2015/05/05
 * BY:           hui.pang
 * PRODUCT NAME:
 * APPLICATION:
 * TARGET H/W:
 * DOC REF:
 *****************************************************************************
 */

#ifndef _UDS_CAN_TRANS_H_
#define _UDS_CAN_TRANS_H_

/*****************************************************************************
**#include 
*****************************************************************************/
#include "system.h"
#include "uds_can_trans_cfg.h"
#include "uds_diag_drv.h"

#pragma CODE_SEG  OTHER_ROM


/*****************************************************************************
**  typedef
*****************************************************************************/
/*
** Structure for describing message to be transmitted.
** msg_length   = total number of bytes in message
** ptr1         = pointer to first N bytes in message
** length1      = number of bytes pointed to by "ptr1"
** ptr2         = pointer to last M bytes in message
** length2      = number of bytes pointed to by "ptr2"
*/
typedef struct
{
    UINT16 msg_length;
    UINT8  *ptr1;
    UINT16 length1;
    UINT8 *ptr2;
    UINT16 length2;
    
} Uds_TxDesc_S;

typedef enum
{
    RX_INFO_INIT        = 0x00,
    RX_MSG_RCVD         = 0x01,
    RX_MSG_INVL_TPCI    = 0x02,
    RX_MSG_PAD_NOT_ZERO = 0x04,
    TX_ABORTED          = 0x08,
    RX_MSG_INVL_LEN     = 0x10,
    RCV_MSG_IS_MSNG     = 0x20, /* the message has been declared missing */
    MSG_NEVER_RCVD      = 0x40, /* if the message has never been received to be used by application level software */
    RCV_MSG_IS_NEW      = 0x80, /* the message is new */

} Uds_RxBufferInfoByte_E;

/*
** Structure which defines diagnostic receive buffer.
** msg_length    = total number of bytes in message
** msg           = message bytes
*/
typedef struct
{
    Uds_RxBufferInfoByte_E info_byte;
    UINT16 msg_length;
    UINT8 msg[RX_MAX_TP_BYTES];
    
} Uds_DiagRxBuffer_S;

/*****************************************************************************
** Constant Macro Definition
*****************************************************************************/
 /*****************************************************************************
** System Macro Definition
*****************************************************************************/
#define DiagDataLength 	  g_cantp_rx_buffer.msg_length
#define DiagBuffer        g_cantp_rx_buffer.msg

/*****************************************************************************
** Action Macro Definition
*****************************************************************************/
    
#define CAN_TRANS_RX(id, dat, length)   do{\
                                            if(id == c_u32_can_rx_diag_id)\
                                            {\
                                                CanTrans_Rx(dat, length, DIAG_PHYSIC_ADDR_MODE);\
                                            }\
                                            else if(id == c_u32_can_rx_fun_diag_id)\
                                            {\
                                                CanTrans_Rx(dat, length, DIAG_FUNCTION_ADDR_MODE);\
                                            }\
                                        }while(0)


/*****************************************************************************
** Config Macro Definition
*****************************************************************************/


/*****************************************************************************
** Task Macro Definition
*****************************************************************************/


/*****************************************************************************
** Variables
*****************************************************************************/
extern BOOL g_cantp_rx_enable;
extern Uds_DiagAddrMode_E g_diag_can_address_mode;  
extern Uds_DiagRxBuffer_S g_cantp_rx_buffer;

/*****************************************************************************
** Constants
*****************************************************************************/


/*****************************************************************************
** Function prototypeseb
*****************************************************************************/
/****************************************************************************/
/**
 * Function Name: CanTrans_ColdInit
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2015/05/05, hui.pang create this function
 ****************************************************************************/
extern void CanTrans_ColdInit( void );

/****************************************************************************/
/**
 * Function Name: CanTrans_Sleep
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2015/05/05, hui.pang create this function
 ****************************************************************************/
extern void CanTrans_Sleep( void );

/*****************************************************************************/
/**
* Function Name: void CanTrans_Wakeup(void)
* Description:   
*
* Param:   none
* Return:  none
* Author:  
******************************************************************************/
extern void CanTrans_Wakeup( void );

/*****************************************************************************/
/**
* Function Name: UINT8 CanTrans_TxMsg(Uds_TxDesc_S *tx_msg_desc)
* Description:   
*
* Param:   Uds_TxDesc_S *tx_msg_desc
* Return:  TRUE/FALSE
* Author:  
******************************************************************************/
extern UINT8 CanTrans_TxMsg( Uds_TxDesc_S *tx_msg_desc );

/****************************************************************************/
/**
 * Function Name: CanTrans_Rx
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2015/05/05, hui.pang create this function
 ****************************************************************************/
extern void CanTrans_Rx( UINT8 *rx_buffer_ptr, UINT8 rxLen, Uds_DiagAddrMode_E mode );

/****************************************************************************/
/**
 * Function Name: CanTrans_Manage
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2015/05/05, hui.pang create this function
 ****************************************************************************/
extern void CanTrans_Manage( void );

/****************************************************************************/
/**
 * Function Name: CanTrans_Handler1ms
 * Description: none
 *
 * Param:   none
 * Return:  none
 * Author:  2015/07/02, hui.pang create this function
 ****************************************************************************/
extern void CanTrans_Handler1ms( void );

/*****************************************************************************
** other
*****************************************************************************/

#pragma CODE_SEG  DEFAULT

/****************************************************************************/

#endif	//_UDS_CAN_TRANS_H_

/*****************************************************************************
** End File
*****************************************************************************/
